<template>
  <div class="app-container">
    <div v-show="active === 1">
      <div class="searchform">
        <!-- 查询条件 -->
        <el-form ref="searchForm" :model="search" size="mini" label-width="90px">
          <el-row :gutter="6">
            <el-col :xs="24" :sm="8" :md="6">
              <el-form-item prop="dealerName" label="代理商名称">
                <el-input v-model="search.dealerName" placeholder="代理商名称" clearable/>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="8" :md="6">
              <el-form-item prop="dataType" label="代理商类型">
                <r-select v-model="search.dataType" type="4508" placeholder="代理商类型" clearable />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="8" :md="6">
              <el-form-item prop="employeeName" label="员工姓名">
                <el-input v-model="search.employeeName" placeholder="员工姓名" clearable/>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="8" :md="6">
              <el-form-item prop="employeeNo" label="员工编号">
                <el-input v-model="search.employeeNo" placeholder="员工编号" clearable />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="8" :md="6">
              <el-form-item prop="userCode" label="用户帐号">
                <el-input v-model="search.userCode" placeholder="员工帐号" clearable/>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="8" :md="6">
              <el-form-item prop="phone" label="手机">
                <el-input v-model="search.phone" placeholder="手机" clearable/>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="8" :md="6">
              <el-form-item prop="isOnjob" label="在职状态">
                <el-select v-model="search.isOnjob" :clearable="true" placeholder="请选择" >
                  <el-option v-for="item in isOnjob" :key="item.code" :label="item.name" :value="item.code">{{ item.name }}</el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <div style="text-align:right">
              <el-button type="primary" icon="el-icon-search" @click="searchHandle">查询
              </el-button>
              <el-button icon="el-icon-refresh" @click="resetForm('searchForm')">重置
              </el-button>
            </div>
          </el-row>
        </el-form>
      </div>
      <!-- 用户列表 -->
      <div class="table">
        <div class="tableHead">
          <div class="tabletitle">员工信息</div>
          <!--<div class="btnGroup">
            <el-button-group>
              <el-button icon="el-icon-plus" type="primary" @click="addDealer">新增用户</el-button>
            </el-button-group>
          </div>-->
          <div class="btnGroup">
            <el-button-group>
              <el-button type="primary" icon="el-icon-edit-outline" @click="editClick" >修改密码</el-button>
              <el-button type="primary" icon="el-icon-refresh" @click="restClick" >重置密码</el-button>
              <el-button :loading="exportLoading" type="primary" icon="el-icon-download" @click="exportData">导出</el-button>
            </el-button-group>
          </div>
        </div>
        <baseTable ref="table" @chaneg-size="changeSizeHandle" @chaneg-page="changePageHandle" @selection-change="handleSelectionChange">
          <el-table-column type="index" label="序号" min-width="50"/>
          <el-table-column type="selection" width="50"/>
          <el-table-column align="center" label="操作" min-width="180">
            <template slot-scope="scope">
              <el-tooltip class="item" content="编辑" placement="bottom">
                <el-button :disabled="scope.row.IS_ONJOB === '10081002'" type="text" style="font-size: 20px;" icon="el-icon-edit-outline" @click="edit(scope.row)"/>
              </el-tooltip>
              <el-tooltip class="item" content="明细" placement="bottom">
                <el-button type="text" style="font-size: 20px;" icon="el-icon-document" @click="detail(scope.row)"/>
              </el-tooltip>
              <el-tooltip class="item" content="解锁" placement="bottom">
                <el-button
                  :disabled="scope.row.LOCK_FLAG === 10041002"
                  type="text"
                  style="font-size: 20px;"
                  icon="el-icon-sold-out"
                  @click="removelock(scope.row)"/>
              </el-tooltip>
              <el-tooltip class="item" content="锁定" placement="bottom">
                <el-button :disabled="scope.row.LOCK_FLAG === 10041001 || scope.row.IS_ONJOB === '10081002'" type="text" style="font-size: 20px;" icon="el-icon-goods" @click="lock(scope.row)"/>
              </el-tooltip>
            </template>
          </el-table-column>
          <el-table-column prop="EMPLOYEE_NO" label="员工编号" min-width="120" />
          <el-table-column prop="USER_CODE" label="员工帐号" min-width="120" />
          <el-table-column :show-overflow-tooltip="true" prop="EMPLOYEE_NAME" label="员工姓名" min-width="150"/>
          <el-table-column :show-overflow-tooltip="true" prop="DEALER_NAME" label="代理商名称" min-width="150"/>
          <el-table-column :formatter="filterCode" label="代理商类型" prop="DATA_TYPE" type="4508"/>
          <el-table-column prop="ROLE_NAME" label="管理岗位" min-width="100"/>
          <el-table-column :formatter="filterCode" prop="GENDER" label="性别" min-width="50" type="1002"/>
          <!--          <el-table-column :formatter="filterCode" prop="POSITION_CODE" label="职位" min-width="100" type="1007"/>-->
          <el-table-column :show-overflow-tooltip="true" prop="CERTIFICATE_ID" label="身份证号" min-width="150"/>

          <el-table-column prop="MOBILE" label="手机" min-width="120"/>
          <el-table-column prop="LOCK_FLAG" label="是否锁定" min-width="100">
            <template slot-scope="scope">
              <el-tag :type="scope.row.LOCK_FLAG === 10041001 ? 'success' : 'primary'" close-transition>{{ scope.row.LOCK_FLAG
              | isYESORNO }}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="IS_ONJOB" label="在职状态" min-width="100">
            <template slot-scope="scope">
              <el-tag :type="scope.row.IS_ONJOB === 10081001 ? 'success' : 'primary'">{{ scope.row.IS_ONJOB |
              isonjobFilter }}
              </el-tag>
            </template>
          </el-table-column>
        </BaseTable>
      </div>
    </div>
    <!-- 弹框 -->
    <el-dialog :title="text" :visible.sync="dialogFormVisible" width="80%" append-to-body >
      <el-form ref="form" :model="form" :rules="rules" :disabled="!bols" label-width="90px">
        <el-collapse v-model="mode">
          <el-collapse-item title="员工基本信息" name="1">
            <el-row :gutter="6">
              <el-col :xs="24" :sm="8" :md="6">
                <el-form-item label="员工编号" prop="EMPLOYEE_NO">
                  <el-input v-model="form.EMPLOYEE_NO" :disabled="bol" placeholder="员工编号" />
                  <el-input v-show="false" v-model="form.EMPLOYEE_ID" placeholder="员工id" />
                  <el-input v-show="false" v-model="form.ORGANIZATION_ID"/>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :sm="8" :md="6">
                <el-form-item label="员工姓名" prop="EMPLOYEE_NAME">
                  <el-input v-model="form.EMPLOYEE_NAME" :disabled="bol" placeholder="员工姓名" />
                </el-form-item>
              </el-col>
              <el-col :xs="24" :sm="8" :md="6">
                <el-form-item label="代理商" prop="DEALER_NAME" >
                  <!--<dealerSelect
                    :disabled="true"
                    ref="dealerSelect"
                    v-model="form.DEALER_NAME"
                    :dealer-name.sync="dealerName"
                    :dealer-dis.sync="dealerDis"
                    :dealer-code-in-name="form.DEALER_NAME"
                    style="width:160px"
                    clearable
                    @getDealerInfo="getDealerInfo"
                    @changeDE="changeDE" />-->
                  <el-input v-model="form.DEALER_NAME" disabled/>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :sm="8" :md="6">
                <el-form-item label="代理商代码" prop="DEALER_CODE">
                  <el-input v-model="form.DEALER_CODE" disabled/>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :sm="8" :md="6">
                <el-form-item label="经度" prop="LONGITUDE">
                  <el-input v-model="form.LONGITUDE" placeholder="经度" disabled/>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :sm="8" :md="6">
                <el-form-item label="纬度" prop="LATITUDE">
                  <el-input v-model="form.LATITUDE" placeholder="纬度" disabled/>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :sm="24" :md="12">
                <el-form-item label="岗位" prop="ROLE" >
                  <el-select v-model="form.ROLE" multiple>
                    <el-option v-for="role in ROLES" :key="role.ROLE_ID" :label="role.ROLE_NAME" :value="role.ROLE_ID"/>
                  </el-select>
                </el-form-item>
                <!--<span v-if="form.STATION === 10061002 || form.STATION === 10061003">
              <el-form-item label="服务等级" prop="TECHNICIAN_GRADE" >
                <r-select v-model="form.TECHNICIAN_GRADE"  placeholder="请选择" type="8004" disabled/>
            </el-form-item></span>-->
                <!--            <span v-else>-->
                <!--             <el-form-item label="服务等级" prop="TECHNICIAN_GRADE" >-->
                <!--              <r-select v-model="form.TECHNICIAN_GRADE" class='search-input' placeholder="请选择" type="8004" ></r-select>-->
                <!--            </el-form-item>-->
                <!--            </span>-->
                <!--<el-form-item label="职位" prop="POSITION_CODE" >
              <r-select v-model="form.POSITION_CODE"  placeholder="请选择" type="1007" clearable/>
            </el-form-item>-->
              </el-col>
              <!--<el-col :xs="24" :sm="8" :md="6">
                <el-form-item label="学历" prop="EDUCATION">
                  <r-select v-model="form.EDUCATION" type="9015" placeholder="请选择" clearable/>
                </el-form-item>
              </el-col>-->
              <!--        -->
              <el-col v-if="form.DATA_TYPE == 45081007" :xs="24" :sm="24" :md="12">
                <el-form-item label="站内身份" prop="SERVICE_POS">
                  <r-select
                    :multiple="true"
                    v-model="form.SERVICE_POS"
                    type="2010"
                    placeholder="请选择"
                  />
                </el-form-item>
              </el-col>

              <el-col :xs="24" :sm="8" :md="6">
                <el-form-item label="性别" prop="GENDER">
                  <r-select
                    v-model="form.GENDER"
                    type="1002"
                  />
                </el-form-item>
              </el-col>
              <el-col :xs="24" :sm="8" :md="6">
                <el-form-item label="出生日期" prop="BIRTHDAY">
                  <el-date-picker v-model="form.BIRTHDAY" type="date" placeholder="出生日期"/>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :sm="8" :md="6">
                <el-form-item label="身份证号" prop="CERTIFICATE_ID">
                  <el-input v-model="form.CERTIFICATE_ID" placeholder="身份证号" />
                </el-form-item>
              </el-col>
              <el-col :xs="24" :sm="8" :md="6">
                <el-form-item label="手机" prop="PHONE">
                  <el-input v-model="form.PHONE" placeholder="手机" />
                </el-form-item>
              </el-col>
              <el-col :xs="24" :sm="8" :md="6">
                <el-form-item label="E_MAIL" prop="E_MAIL">
                  <el-input v-model="form.E_MAIL" placeholder="E_MAIL" />
                </el-form-item>
              </el-col>
              <el-col :xs="24" :sm="8" :md="6">
                <el-form-item label="邮编" prop="ZIP_CODE">
                  <el-input v-model="form.ZIP_CODE" placeholder="邮编" />
                </el-form-item>
              </el-col>
              <el-col :xs="24" :sm="8" :md="6">
                <el-form-item prop="IS_ONJOB" label="在职状态">
                  <el-select v-model="form.IS_ONJOB" :clearable="true" placeholder="请选择" @change="isOnjobChange">
                    <el-option v-for="item in isOnjob" :key="item.code" :label="item.name" :value="item.code">{{ item.name }}</el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :sm="8" :md="6">
                <el-form-item label="离职日期" prop="DIMISSION_DATE">
                  <el-date-picker v-model="form.DIMISSION_DATE" :disabled="true" type="date" placeholder="离职日期"/>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :sm="8" :md="6">
                <el-form-item label="建档日期" prop="FOUND_DATE" type="date">
                  <el-date-picker v-model="form.FOUND_DATE" :disabled="bol" class="form-input" type="date" placeholder="建档日期"/>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :sm="24" :md="12">
                <el-form-item label="地址" prop="ADDRESS">
                  <el-input v-model="form.ADDRESS" placeholder="地址" />
                </el-form-item>
              </el-col>
            </el-row>
          </el-collapse-item>
        </el-collapse>
      </el-form>
      <div slot="footer" class="dialog-footer" style="text-align:center">
        <el-button v-show="bols" type="primary" @click="save">保 存</el-button>
        <el-button @click="cancel()">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog v-dialogDrag :title="'更改密码'" :visible.sync="passwordDialogFormVisible" width="30%">
      <div class="elform">
        <el-form ref="addSearchForm" :inline="true" :model="addSearch" :rules="passwordRules" size="mini" label-width="120px" >
          <el-form-item label="密码" prop="newPassword">
            <el-input v-model="addSearch.newPassword" type="password" auto-complete="off"/>
          </el-form-item>
          <el-form-item label="确认密码" prop="checkPass">
            <el-input v-model="addSearch.checkPass" type="password" auto-complete="off"/>
          </el-form-item>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer" align="center">
        <el-button type="text"><i class="el-icon-search magnifier"/></el-button>
        <el-button type="primary" @click="savePwd">更改</el-button>
        <el-button @click="cancelPwd()">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
// import {
//   msg,
//   getJsonTree
// } from '@/utils/index'
import {
  getDealerUsersList,
  findTcCodeByType,
  addUserInfo,
  getUserInfoById,
  getUserRoles,
  editUserInfo,
  exportDeaEmpForSearch
} from '@/api/admin/org/gms/employeeInfo'
import { removeLockflag,
  lockflag } from '@/api/admin/auth/employeePermissionInfo'
import BaseTable from '@/components/BaseTable'
import filtercode from '@/components/Checkbox/filtercode'
import PositionTypeSelect from '@/components/Select/positionTypeSelect'
import WorkGroupSelect from '@/components/Select/workGroupSelect'
import WorkerTypesSelect from '@/components/Select/workerTypesSelect'
import RepairPositionsSelect from '@/components/Select/repairPositionsSelect'
import rSelect from '@/components/Select/Select'
import formMixins from '@/mixins/formMixins'
import Gender from '@/components/Select/gender'
import IsOnjob from '@/components/Select/isOnjob'
import departmentSelect from './departmentSelect'
import dealerSelect from './dealerSelect'
import { exportFile } from '@/utils'
import { editPassword, restPassword } from '@/api/admin/auth/gms/user'

// import {
//   formatDate
// } from 'element-ui/packages/date-picker/src/util'
import _ from 'lodash'
import { phone, IDNumber, email, zipCode, passWD } from '@/utils/validator'
export default {
  name: 'DealerEmployeeInfo',
  components: {
    BaseTable,
    PositionTypeSelect,
    WorkGroupSelect,
    WorkerTypesSelect,
    RepairPositionsSelect,
    rSelect,
    Gender,
    IsOnjob,
    filtercode,
    departmentSelect,
    dealerSelect
  },
  // 过滤器
  filters: {
    isonjobFilter(val) {
      return val === 10081001 ? '在职' : '离职'
    },
    isYESORNO(val) {
      return val === 10041001 ? '是' : '否'
    },
    datasourcesFilter(val) {
      return val === 10451001 ? '店面' : '厂端'
    },
    genderFilter(val) {
      if (val === 10021001) {
        return '男'
      }
      if (val === 10021002) {
        return '女'
      }
      if (val === 10021003) {
        return '未知'
      }
    }
  },
  mixins: [formMixins],
  data() {
    // 校验新密码
    const validateNewPassword = (rule, value, callback) => {
      if (_.isEmpty(value)) {
        callback(new Error('请输入新密码'))
      } else {
        passWD(rule, value, callback)
      }
    }
    // 校验第二次和第一次输入的密码是否一致
    const validateConfirmPassword = (rule, value, callback) => {
      if (_.isEmpty(value)) {
        callback(new Error('请再次输入密码'))
      } else if (value !== this.addSearch.newPassword) {
        callback(new Error('两次输入密码不一致!'))
      } else {
        passWD(rule, value, callback)
      }
    }
    return {
      multipleSelection: [],
      ROLES: [],
      active: 1,
      mode: ['1', '2'],
      way: '',
      text: '',
      bol: false,
      bols: true,
      exportLoading: false,
      dialogFormVisible: false,
      passwordDialogFormVisible: false,
      addSearch: {
        empIds: '',
        newPassword: '',
        checkPass: ''
      },
      passwordRules: {
        newPassword: [{
          validator: validateNewPassword,
          trigger: 'blur',
          required: true
        }],
        checkPass: [{
          validator: validateConfirmPassword,
          trigger: 'blur',
          required: true
        }]
      },
      // 在职状态
      isOnjob: [{
        code: 10081001,
        name: '在职'
      },
      {
        code: 10081002,
        name: '离职'
      }
      ],
      rules: {
        EMPLOYEE_NO: [{
          required: true,
          message: '请填写员工编号',
          trigger: 'blur'
        }
        ],
        ROLE: [
          { required: true, message: '请填写岗位', trigger: 'blur' }
        ],
        EMPLOYEE_NAME: [{
          required: true,
          message: '请填写员工姓名',
          trigger: 'blur'
        }],
        DEALER_NAME: [{
          required: true,
          message: '请选择代理商',
          trigger: 'blur'
        }],
        IS_ONJOB: [{
          required: true,
          message: '请选择在职状态',
          trigger: 'blur'
        }],
        PRODUCT_TYPE: [{
          required: true,
          message: '请选择技师等级',
          trigger: 'blur'
        }],
        STATION: [{
          required: true,
          message: '请选择岗位',
          trigger: 'blur'
        }],
        // MOBILE: [{
        //   trigger: "blur",validator: mobilePhone
        // }],
        CERTIFICATE_ID: [{
          trigger: 'blur', validator: IDNumber
        }],
        E_MAIL: [{
          trigger: 'blur', validator: email
        }],
        ZIP_CODE: [{
          trigger: 'blur', validator: zipCode
        }],
        PHONE: [{
          required: true,
          message: '请填写手机',
          trigger: 'blur'
        },
        { trigger: 'blur', validator: phone }]
      },
      search: {
        limit: 10,
        pageNum: 1,
        employeeName: '',
        dealerName: '',
        dataType: '',
        userCode: '',
        orgName: '',
        isOnjob: '',
        employeeNo: '',
        phone: ''
      },
      form: {
        EMPLOYEE_NO: '',
        EMPLOYEE_NAME: '',
        LONGITUDE: '',
        LATITUDE: '',
        EDUCATION: '',
        CERTIFICATE_ID: '',
        E_MAIL: '',
        ROLE: '',
        ZIP_CODE: '',
        PHONE: '',
        BIRTHDAY: '',
        GENDER: '',
        WORKGROUP_CODE: '',
        DIMISSION_DATE: '',
        FOUND_DATE: '',
        ADDRESS: '',
        IS_ONJOB: '',
        STATION: '',
        TECHNICIAN_GRADE: '',
        POSITION_CODE: '',
        DEALER_NAME: '',
        DEALER_CODE: '',
        SERVICE_POS: [],
        DATA_TYPE: ''
      },
      checkedList: [],
      sites: [],
      organization: {
        ORGANIZATION_ID: '',
        ORG_NAME: ''
      },
      key: '',
      tree: [],
      loading: false,
      dealercode: '',
      dealerDis: false,
      dealerName: '',
      isST: false
    }
  },
  computed: {},
  mounted() {
    this.searchHandle()
  },
  methods: {
    // 查询
    searchHandle() {
      const table = this.$refs['table']
      table.wait()
      getDealerUsersList(this.search)
        .then(res => {
          table.complete().filData(res)
          this.dealercode = res.rows[0].DEALER_CODE
        })
        .catch(err => {
          table.complete()
        })
    },
    removelock(data) {
      this.$confirm('是否解锁', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          removeLockflag(data.EMPLOYEE_ID).then(res => {
            this.$message({
              type: 'success',
              message: '解锁成功!'
            })
            this.searchHandle()
          })
            .catch(err => {
            })
        })
        .catch(err => {
          this.$message({
            type: 'info',
            message: '已取消解锁'
          })
        })
    },

    // 锁定
    lock(data) {
      this.$confirm('是否锁定', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          lockflag(data.EMPLOYEE_ID).then(res => {
            this.$message({
              type: 'success',
              message: '锁定成功!'
            })
            this.searchHandle()
          })
            .catch(err => {
            })
        })
        .catch(err => {
          this.$message({
            type: 'info',
            message: '已取消锁定'
          })
        })
    },
    // changeTechnicianGrade(){
    //   if(this.form.STATION === 10061001 || this.form.STATION === 10061004){
    //     this.$set(this.form,'TECHNICIAN_GRADE',80041005);
    //   }
    // },

    getDealerInfo(val) {
      this.$set(this.form, 'DEALER_NAME', val.DEALER_NAME)
      this.$set(this.form, 'DEALER_CODE', val.DEALER_CODE)
      this.$set(this.form, 'LONGITUDE', val.LONGITUDE)
      this.$set(this.form, 'LATITUDE', val.LATITUDE)
    },
    changeDE() {
      this.form.DEALER_NAME = ''
      this.form.LONGITUDE = ''
      this.form.LATITUDE = ''
    },
    getEmployeeRoles() {
      const type = 1006
      findTcCodeByType(type)
        .then(res => {
          this.sites = _.cloneDeep(res)
        })
        .catch(err => {
          // table.complete()
        })
    },
    EmployeeRolesCheck(data) {
      this.$nextTick(() => {
        this.$refs.form.resetFields()
        this.form = {}
      })
      const id = data.EMPLOYEE_ID
      // this.getEmployeeRoles()
      getUserInfoById(id)
        .then(item => {
          this.form = _.cloneDeep(item)
          if (this.form.SERVICE_POS != null && this.form.SERVICE_POS.length > 0) {
            this.form.SERVICE_POS = this.form.SERVICE_POS.split(',')
            for (var i = 0; i < this.form.SERVICE_POS.length; i++) {
              this.form.SERVICE_POS[i] = parseInt(this.form.SERVICE_POS[i])
            }
          }
          getUserRoles(item.DEALER_CODE).then(res => {
            this.ROLES = res
          })
        })
        .catch(err => {
        })
    },
    // 打开编辑框
    edit(data) {
      this.text = '员工信息编辑'
      this.way = 'edit'
      this.dealerDis = false
      this.bol = true
      this.bols = true
      this.dialogFormVisible = true
      this.EmployeeRolesCheck(data)
    },
    // 新增
    addDealer() {
      this.text = '员工信息新增'
      this.way = 'addDealer'
      this.dealerDis = false
      this.bol = false
      this.bols = true
      this.dialogFormVisible = true
      // const fouddate = formatDate(new Date(), 'yyyy-MM-dd')
      this.getEmployeeRoles()
    },
    // 明细
    detail(data) {
      this.text = '员工信息明细'
      this.bol = true
      this.dealerDis = true
      this.bols = false
      this.dialogFormVisible = true
      this.EmployeeRolesCheck(data)
    },
    // 新增确认
    save() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          const params = {
            isDealer: this.way,
            isST: this.isST,
            employeeNo: this.form.EMPLOYEE_NO,
            employeeName: this.form.EMPLOYEE_NAME,
            organizationId: this.form.ORGANIZATION_ID,
            gender: this.form.GENDER,
            birthday: this.form.BIRTHDAY,
            certificateId: this.form.CERTIFICATE_ID,
            phone: this.form.PHONE,
            eMail: this.form.E_MAIL,
            role: this.form.ROLE,
            zipCode: this.form.ZIP_CODE,
            isOnjob: this.form.IS_ONJOB,
            dimissionDate: this.form.DIMISSION_DATE,
            foundDate: this.form.FOUND_DATE,
            address: this.form.ADDRESS,
            defaultPosition: this.form.LABOUR_POSITION_CODE,
            station: this.form.STATION,
            dealerName: this.form.DEALER_NAME,
            dealerCode: this.form.DEALER_CODE,
            longitudes: this.form.LONGITUDE,
            latitudes: this.form.LATITUDE,
            technicianGrade: this.form.TECHNICIAN_GRADE,
            positionCode: this.form.POSITION_CODE,
            education: this.form.EDUCATION,
            servicePos: this.form.SERVICE_POS
          }
          // if (this.form.LONGITUDE === '' || this.form.LONGITUDE === null ||
          //     this.form.LATITUDE === '' || this.form.LATITUDE === null) {
          //   this.$message({
          //     type: 'warning',
          //     message: '请先维护坐标!'
          //   })
          //   return false
          // } else {
          if (this.way === 'addDealer') {
            addUserInfo(params).then(res => {
              this.$message({
                type: 'success',
                message: '员工信息保存成功!'
              })
              this.cancel()
              this.dialogFormVisible = false
              this.searchHandle()
            }).catch(err => {
              this.$message({
                type: 'error',
                message: err.response.data.errorMsg
              })
            })
          }
          if (this.way === 'edit') {
            editUserInfo(params, this.form.EMPLOYEE_ID).then(res => {
              this.$message({
                type: 'success',
                message: '员工信息保存成功!'
              })
              this.cancel()
              this.dialogFormVisible = false
              this.searchHandle()
            }).catch(err => {
              this.$message({
                type: 'error',
                message: err.response.data.errorMsg
              })
            })
          }
        }
      })
    },
    // 选择行数据
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    // 修改密码
    editClick() {
      if (this.multipleSelection.length !== 0) {
        let empIds = ''
        this.multipleSelection.forEach(item => {
          if (empIds === '') {
            empIds = item['EMP_ID']
          } else {
            empIds = empIds + ',' + item['EMP_ID']
          }
        })
        this.passwordDialogFormVisible = true
        this.addSearch = {
          empIds: empIds,
          newPassword: '',
          checkPass: ''
        }
        this.$nextTick(() => {
          this.$refs.addSearchForm.clearValidate()
        })
      } else {
        this.$message({
          type: 'warning',
          message: '请选择表格数据'
        })
      }
    },
    // 重置密码
    restClick() {
      if (this.multipleSelection.length !== 0) {
        let empIds = ''
        this.multipleSelection.forEach(item => {
          if (empIds === '') {
            empIds = item['EMP_ID']
          } else {
            empIds = empIds + ',' + item['EMP_ID']
          }
        })
        const param = {
          empIds: empIds,
          newPassword: 'SHANTUI123456'
        }
        restPassword(param)
          .then(() => {
            this.$message({
              type: 'success',
              message: '重置密码成功!'
            })
          }).catch(err => {

          })
      } else {
        this.$message({
          type: 'warning',
          message: '请选择表格数据'
        })
      }
    },
    cancel() {
      this.form = {}
      this.text = ''
      this.way = ''
      this.bol = false
      this.bols = true
      this.dialogFormVisible = false
    },
    // 在职状态改变事件
    isOnjobChange() {
      if (this.form.IS_ONJOB === 10081002) {
        this.form.DIMISSION_DATE = new Date()
      } else {
        this.form.DIMISSION_DATE = ''
      }
    },
    // 取消
    cancelPwd() {
      this.passwordDialogFormVisible = false
    },
    // 保存
    savePwd() {
      this.$refs['addSearchForm'].validate(valid => {
        if (valid) {
          const param = {
            empIds: this.addSearch.empIds,
            newPassword: this.addSearch.newPassword
          }
          editPassword(param)
            .then(() => {
              this.$message({
                type: 'success',
                message: '修改密码成功!'
              })
              this.passwordDialogFormVisible = false
            }).catch(err => {

            })
        }
      })
    },
    // 导出Excel(前端实现)
    exportData() {
      this.exportLoading = true
      exportDeaEmpForSearch(this.search)
        .then(res => {
          const option = {
            tHeader: ['员工编号', '员工姓名', '代理商', '代理商代码', '经度', '纬度', '岗位', '性别', '出生日期', '身份证号',
              '手机', 'E_MAIL', '邮编', '在职状态', '离职日期', '建档日期', '地址'],
            filterVal: ['EMPLOYEE_NO', 'EMPLOYEE_NAME', 'DEALER_NAME', 'DEALER_CODE', 'LONGITUDE', 'LATITUDE', 'ROLE_NAME', 'GENDER', 'BIRTHDAY', 'CERTIFICATE_ID',
              'PHONE', 'E_MAIL', 'ZIP_CODE', 'IS_ONJOB', 'DIMISSION_DATE', 'FOUND_DATE', 'ADDRESS'],
            table: res,
            fileName: '员工信息明细'
          }
          exportFile(option, () => {
            this.exportLoading = false
          })
        })
        .catch(err => {})
    }
  }
}

</script>

<style scoped>
</style>
